home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3 .adf / Exec / piarc.LZH / dkbr.rexx < prev    next >
OS/2 REXX Batch file  |  1992-02-29  |  7KB  |  277 lines

  1. /*
  2.  * dkbr.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: January 17th, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate targar.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41. options;
  42. address;
  43.  
  44.   /*
  45.    * This code attempts to read a file called "picmdpath" from REXX:
  46.    * If it can't find it, the script will assume that the commands
  47.    * associated with this PI Module are in "c:". If the file exists,
  48.    * the script will look in the path that is specified in the file.
  49.    * If you create this file, you MUST put a complete, correct path
  50.    * in it; if the commands are in a sub-directory, you have to put
  51.    * the trailing slash on the path (like, device:dir/).
  52.    * 
  53.    */
  54.   cmdpath = 'c:';
  55.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  56.     do
  57.       cmdpath = readln(fhandle);
  58.       call close(fhandle);  /* close the file    */
  59.     end
  60.  
  61.   prevpath = 'ram:'; /* put user in ram to start with... */
  62.  
  63.   if show('C',dkbpath) = 1 then do
  64.     prevpath = getclip(dkbpath);
  65.     end;
  66.  
  67.   address(prtnme);
  68.   options results;
  69.   'current';
  70.   bufdata = result; /* get name of buffer, if there is one */
  71.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  72.   if bname ~= '<none>' then do
  73.     bufname = bname;
  74.     end;
  75.   if (length(bufname) > 4) then do
  76.     epos = pos('.dis',bufname,length(bufname)-4);
  77.     if epos ~= 0 then do
  78.       bufname = left(bufname,epos-1)
  79.       end
  80.     end;
  81.   'filerequest "'||prevpath||'","'||bufname||'",".dis","Load DKB"';
  82.   DKBfile = result;
  83.   options;
  84.  
  85.   if DKBfile = 'FR_CANCELLED' then do
  86.     address(prtnme);
  87.     'imtofront';
  88.     exit 0;
  89.     end;
  90.  
  91.   DKBfile = expandfilename(DKBfile);
  92.   thispath = gimmepath(DKBfile);
  93.   call setclip(dkbpath,thispath);
  94.  
  95.   address command cmdpath||'DKBRD c "'||DKBfile||'"';
  96.   if rc ~= 0 then do
  97.     address(prtnme);
  98.     'message "Cannot read '||DKBfile||'"';
  99.     exit 0; /* this is not a proper DKB file */
  100.     end;
  101.  
  102.   call open(fhandle,'ram:IP_LDDKB.tmp','read');      /* open the file */
  103.   rstring = readln(fhandle);
  104.   call close(fhandle);                     /* close the file    */
  105.   
  106.   address command 'c:delete >nil: ram:IP_LDDKB.tmp';
  107.   
  108.   parse var rstring width '/' height
  109.  
  110.   if height < 0 then do
  111.     'message "Bad Height: '||height||'"';
  112.     exit 0;
  113.     end;
  114.  
  115.   if height > 32767 then do
  116.     'message "Bad Height: '||height||'"';
  117.     exit 0;
  118.     end;
  119.  
  120.   if width < 0 then do
  121.     'message "Bad Width: '||width||'"';
  122.     exit 0;
  123.     end;
  124.  
  125.   if width > 32767 then do
  126.     'message "Bad Width: '||width||'"';
  127.     exit 0;
  128.     end;
  129.  
  130.   address(prtnme);
  131.   
  132.   'imtofront'; /* show user the IM screen */
  133.   /* is there already a primary buffer??? */
  134.   options results;
  135.   'current';
  136.   bufdata = result;
  137.   options;
  138.  
  139.   mknewbuff = 1;
  140.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  141.   if bname ~= '<none>' then
  142.     do
  143.       address(prtnme);
  144.       options results;
  145.       if (bx = width) & (by = height) then
  146.         do
  147.           'askyn '||'"Merge Primary ['||bname||']" "New Buffer"'
  148.           prefs = result;
  149.           options;
  150.           address;
  151.           if prefs = 0 then
  152.             do
  153.               address(prtnme);
  154.               'rename '||bnum||' 'gxname;
  155.               mknewbuff = 0;
  156.               address;
  157.             end;
  158.           else
  159.             do
  160.               mknewbuff = 1;
  161.               'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  162.               prefs = result;
  163.               options;
  164.               address;
  165.               if prefs = 0 then
  166.                 do
  167.                   address(prtnme);
  168.                   'killbuff '||bnum; /* this kills the Primary Buffer */
  169.                   address;
  170.                 end;
  171.             end;
  172.         end;
  173.       else
  174.           do
  175.             mknewbuff = 1;
  176.             'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  177.             prefs = result;
  178.             options;
  179.             address;
  180.             if prefs = 0 then
  181.               do
  182.                 address(prtnme);
  183.                 'killbuff '||bnum; /* this kills the Primary Buffer */
  184.                 address;
  185.               end;
  186.           end;
  187.     end;
  188.  
  189.   if mknewbuff = 1 then do
  190.     /* New buffer is created at current resolution */
  191.     address(prtnme);
  192.     'autoredraw 0';
  193.     options results;
  194.     'newbuf '||width||' '||height;
  195.     if rc ~= 0 then do
  196.       "message Can't allocate buffer!";
  197.       'autoredraw 1';
  198.       exit 0;
  199.       end
  200.     bnum = result;
  201.     options;
  202.     'newcurrent '||bnum;
  203.     'rename '||bnum||' 'gxname;
  204.     'autoredraw 1';
  205.     address;
  206.   end;
  207.  
  208.   address(prtnme);
  209.   options results;
  210.   'jackin';
  211.   jackadr = result;
  212.   options;
  213.  
  214.   'wbtofront';
  215.   'lockimage '||bnum;
  216.   address command cmdpath||'DKBRD d'||jackadr||' "'||DKBfile||'"';
  217.   'unlockimage '||bnum;
  218.  
  219.   address(prtnme);
  220.   'imtofront';
  221.   'redraw';
  222.   address;
  223.  
  224.   exit 0;
  225.  
  226. /*
  227.  * gimmepath
  228.  *
  229.  * This takes the provided argument and sucks the path out of it, then
  230.  * returns that path to the caller, sans file name.
  231.  */
  232. gimmepath:
  233.   arg fullnamegx;
  234.     tempgx = reverse(fullnamegx);
  235.     lengx = length(fullnamegx);   /* get length of string */
  236.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  237.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  238.     seploc = 0; /* assumes current dir, no path supplied */
  239.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  240.       seploc = (lengx - slashdex)+1;
  241.       end;
  242.     else do
  243.       if colondex ~= 0 then do /* we assume we are on a device */
  244.         seploc = (lengx - colondex)+1;
  245.         end;
  246.       end;
  247.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  248.   gxpath = left(fullnamegx,seploc);
  249.   return(gxpath);
  250.  
  251. /*
  252.  * Since this script can't be expected to know where the CD of the user
  253.  * is when this cmd is invoked, we have to check the path the user
  254.  * provides - if it's not specified right from a root, then we have
  255.  * to make it a complete specification from the root.
  256.  */
  257. expandfilename:
  258.   parse arg jfile;
  259.   if index(jfile,':') = 0 then do
  260.     curdir = pragma(D);
  261.     if right(curdir,1) ~= ':' then do
  262.       if right(curdir,1) ~= '/' then do
  263.         if curdir ~= '' then do
  264.           curdir = curdir || '/';
  265.           end;
  266.         end;
  267.       end;
  268.     jfile = curdir||jfile;
  269.     end;
  270.   return(jfile);
  271.  
  272. rvalue:
  273.   wordnum = c2d(readch(fhandle,1)) * 256;
  274.   wordnum = wordnum + c2d(readch(fhandle,1));
  275.   return wordnum;
  276.  
  277.